using Kitware.VTK;
using System;

/// <summary>
/// Class containing main method
/// </summary>
public class VRExampleClass
{
    /// <summary>
    /// A console application that creates a 
    /// vtkRenderWindow without a Windows Form
    /// </summary>
    /// <param name="argv"></param>
    public static void Main(String[] argv)
    {
		renderer = vtkVRRenderer.New();
        renWin = vtkVRRenderWindow.New();
		iren = vtkVRRenderWindowInteractor.New();
		camera = vtkVRCamera.New();
		
		renderer.SetBackground(0.2, 0.3, 0.4);
        renWin.AddRenderer(renderer);
        iren.SetRenderWindow(renWin);
        renderer.SetActiveCamera(camera);
		
        sphere = vtkSphereSource.New();
	    sphere.SetPhiResolution(100);

        sphereMapper = vtkPolyDataMapper.New();
        sphereMapper.SetInputConnection(sphere.GetOutputPort());

        sphereActor = vtkActor.New();
        sphereActor.SetMapper(sphereMapper);
        sphereActor.VisibilityOn();

		renderer.AddActor(sphereActor);

        renWin.Render();
        // render the image
        iren.Initialize();
        iren.Start();
        //Clean up
        deleteAllVTKObjects();
    }

    static vtkSphereSource sphere;
    static vtkPolyDataMapper sphereMapper;
    static vtkActor sphereActor;
	static vtkPLYReader reader;
    static vtkVRRenderer renderer;
    static vtkVRRenderWindow renWin;
    static vtkVRRenderWindowInteractor iren;
	static vtkVRCamera camera;


    ///<summary>
    ///Deletes all static objects created
    ///</summary>
    public static void deleteAllVTKObjects()
    {
        //clean up vtk objects
        if (reader != null) { reader.Dispose(); }
		if (sphere != null) { sphere.Dispose(); }
        if (sphereMapper != null) { sphereMapper.Dispose(); }
        if (sphereActor != null) { sphereActor.Dispose(); }
        if (renderer != null) { renderer.Dispose(); }
        if (renWin != null) { renWin.Dispose(); }
        if (iren != null) { iren.Dispose(); }
		if (camera != null) { camera.Dispose(); }
    }
}

